#pragma once
#include "gamecomponent.h"
#include "graphics/GrVector.h"
#include <GL/glu.h>

#define M_PI 3.14159265

class CSpriteComponent :
	public CGameComponent
{
protected:
	CGrVector _position;
	double _rotation; //we restrict all up vectors to (0, 1, 0), so rotation is a scalar in the x-z plane

	GLUquadricObj *_quadratic;


	void drawSphere(double r, int lats, int longs) 
	{
		int i, j;
		for(i = 0; i <= lats; i++) 
		{
			double lat0 = M_PI * (-0.5 + (double) (i - 1) / lats);
			double z0  = r * sin(lat0);
			double zr0 = r * cos(lat0);

			double lat1 = M_PI * (-0.5 + (double) i / lats);
			double z1 = r * sin(lat1);
			double zr1 = r * cos(lat1);

			glBegin(GL_QUAD_STRIP);
			for(j = 0; j <= longs; j++) 
			{
				double lng = 2 * M_PI * (double) (j - 1) / longs;
				double x = cos(lng);
				double y = sin(lng);

				glNormal3f(GLfloat(x * zr0), GLfloat(y * zr0), GLfloat(z0));
				glVertex3f(GLfloat(x * zr0), GLfloat(y * zr0), GLfloat(z0));
				glNormal3f(GLfloat(x * zr1), GLfloat(y * zr1), GLfloat(z1));
				glVertex3f(GLfloat(x * zr1), GLfloat(y * zr1), GLfloat(z1));
			}
			glEnd();
		}
	}


public:
	CSpriteComponent(void)  
	{ 
		_position = CGrVector(0, 0, 0); 
		_rotation = 0;

		_quadratic = gluNewQuadric();
		gluQuadricNormals(_quadratic, GLU_SMOOTH);
	}
	virtual ~CSpriteComponent(void) { gluDeleteQuadric(_quadratic); }

	virtual void Render() = 0;
	virtual void Update(double dt) = 0;

	//accessors
	CGrVector getPosition() { return _position; }
	double getRotation() { return _rotation; }
	void setRotation(double angle) { _rotation = angle; }
	void setPosition(CGrVector p) { _position = p; }



private: //negation
	CSpriteComponent(const CSpriteComponent&);
};
